package com.brower.project.ui.viewmodel

import android.text.TextUtils
import com.brower.project.base.BaseViewModel

class RegisterViewModel : BaseViewModel() {
    private var useName: String? = null
    private var psd: String? = null
    private var rePsd: String? = null
    val usernameAfterChanged: (String) -> Unit = {
        useName = it
    }

    val psdAfterChanged: (String) -> Unit = {
        psd = it
    }

    val rePsdAfterChanged: (String) -> Unit = {
        rePsd = it
    }

    fun register() {
        if (TextUtils.isEmpty(useName)) {
            showToast("用户名不能为空")
            return
        }
        if (TextUtils.isEmpty(psd)) {
            showToast("密码不能为空")
            return
        }
        if (!TextUtils.equals(psd, rePsd)) {
            showToast("两次密码不一致")
            return
        }
        showLoadView()
        launchFlow(
            request = { service.register(useName!!, psd!!, rePsd!!) },
            resp = {},
            complete = { dismissLoadView() }
        )
    }
}